package com.witframework.core.log;

import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;





/**
 * 系统日志的print输出实现
 * @author wuxinyang
 *
 */
public class PrintLogger implements AuditLogger {
	static Logger logger = Logger.getLogger(PrintLogger.class);
	static boolean printLog=false;
	public void info(String user_id, Date date_time, String return_code,
			String error_description, Date duration, String client_ip,
			String operation, String object_id, String transaction_data) {
		if(printLog)
		logger.info("audit[PrintLogger]:\n" +
				"user_id\tdate_time\treturn_code\t" +
				"error_description\tduration\tclient_ip\toperation\tobject_id\ttransaction_data\n"
				+user_id+"\t"
				+date_time+"\t"+return_code+"\t"
				+error_description+"\t"+duration+"\t"+client_ip
				+"\t"+operation+"\t"+object_id+"\t"+transaction_data);

	}

	public void info(HttpServletRequest request,String return_code,
			String error_description, Date duration, String operation,
			String object_id, String transaction_data) {
		String remoteAddr = request.getRemoteAddr();
		String user="";
		if(request.getUserPrincipal()!=null)
			user=request.getUserPrincipal().getName();
		else if(request.getRemoteUser()!=null)
			user=request.getRemoteUser();
		else
			user="anonymous";
		info(user,new Date(),return_code,error_description,duration,remoteAddr,operation,object_id,transaction_data);

	}


}
